import ts from 'rollup-plugin-typescript2';
import serve from 'rollup-plugin-serve';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default {
    input: resolve(__dirname, 'src/index.ts'),
    output: {
        file: resolve(__dirname, 'dist/bundle.js'),
        format: 'iife', // 立即执行函数
        name: 'MyLibrary', // export 导出时会显示这个名称
        sourcemap: true
    },
    plugins: [
        nodeResolve({
            extensions: ['.js', '.ts']
        }),
        ts({
            tsconfig: resolve(__dirname, 'tsconfig.json'),
            useTsconfigDeclarationDir: true
        }),
        serve({
            port: 3000,
            open: false,
            openPage: '/index.html',
            contentBase: [__dirname]
        }),
        livereload({
            watch: [resolve(__dirname, 'dist')],
            delay: 100,
            verbose: true
        }),
    ],
    watch: {
        include: 'src/**',
        exclude: 'node_modules/**',
        verbose: true
    }
};
